﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SyncLib;
using AppCommon.Controls;
using AppCommon;
using SyncApplication.Dialog;
using DevComponents.DotNetBar.SuperGrid;

namespace SyncConfig.Controls
{
    public partial class ClientHistorySummary : UserControlBase
    {
        public ClientHistorySummary()
        {
            InitializeComponent();
            historySyncTableAdapter.Connection.ConnectionString = CommonVariable.SqlConnectionString;
            if (!DesignMode)
            {
                GridDateTimeInputEditControl c = (GridDateTimeInputEditControl)GridMain.PrimaryGrid.Columns["SyncDate"].RenderControl;
                c.Format = DevComponents.Editors.eDateTimePickerFormat.Custom;
                c.CustomFormat = "dd/MM/yyyy HH:mm:ss";
                GridMain.PrimaryGrid.Columns["Result"].RenderType = typeof(SyncApplication.Controls.ClientConfig.MyGridImageControl);
            }
        }
        public bool ShowChoiceColumn
        {
            get
            {
                return GridMain.PrimaryGrid.Columns["Choice"].Visible;
            }
            set
            {

                GridMain.PrimaryGrid.ShowCheckBox = value;
                GridMain.PrimaryGrid.Columns["Choice"].Visible = value;
            }
        }
        public void DataBindSummary()
        {
            historySyncTableAdapter.Fill(syncHistoryDS.HistorySync);
        }
        public void DataBind()
        {
            historySyncTableAdapter.FillByTop100(syncHistoryDS.HistorySync);
        }
        private void superGridControl1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
                DataBind();
        }

        private void GridMain_RowDoubleClick(object sender, DevComponents.DotNetBar.SuperGrid.GridRowDoubleClickEventArgs e)
        {
            SyncHistoryDS.HistorySyncRow row = GridMain.GetDataRow<SyncHistoryDS.HistorySyncRow>(e.GridRow.RowIndex);
            DetailSync frm = new DetailSync();
            frm.ShowMessage(row.CopeName + "[" + row.Result + "]", row.Comment, row);
            frm.Dispose();
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            if (dtiFromDate.ValueObject != null && dtiToDate.ValueObject != null)
                historySyncTableAdapter.FillByDate(syncHistoryDS.HistorySync, dtiFromDate.Value, dtiToDate.Value);
        }

    }
}
